﻿--获得icp数据
CREATE PROCEDURE [dbo].[proc_SiteICP_GetList]
(
	@startIndex int,
	@endIndex int,
	@docount bit,
	@customer varchar(50),--客户名称
	@category varchar(20), --类别
	@username varchar(20)
)
as
--公司Id
declare @companyid int
set @companyid = (select companyid from aspnet_Users where username=@username)

set nocount on
	if(@docount=1)
		select *,'' as StateName  from SiteICP where customername like '%'+@customer+'%' and (case (isnull(icp_num,'0')) when '0' then '0' else '1' end) like '%'+@category+'%' 
	else
	begin
	declare @indextable table(id int identity(1,1),nid int)
	set rowcount @endIndex
	insert into @indextable(nid) select id from SiteICP where customername like '%'+@customer+'%' and (case (isnull(icp_num,'0')) when '0' then '0' else '1' end) like '%'+@category+'%'
	select 
		icp.*
		,(select ss.title from ProjectState ss where ss.ProjectId=icp.stateid) as StateName
	from SiteICP icp
	inner join @indextable t on 
	icp.id=t.nid
	where 
		t.id between @startIndex and @endIndex 
	order by t.id
	end
set nocount off
RETURN